package gui;

import abstratos.GUI;
import abstratos.Observador;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class TelaPrincipal extends javax.swing.JFrame implements GUI {

    private TelaVenda telaVenda;
    
    public TelaPrincipal() {
        initComponents();
        adicionarListeners();
        this.setVisible(true);
        this.setExtendedState(Frame.MAXIMIZED_BOTH);
        telaVenda = new TelaVenda(this, false);
    }

    public void adicionarListeners()
    {
        MenuListener listener = new MenuListener();
        mSair.addActionListener(listener);
        mVenda.addActionListener(listener);
    }

    public void configurarTabela() {
        throw new UnsupportedOperationException("configurarTabela não implementado nesta classe.");
    }

    public static Observador getTelaConsultaEstoque() {
        return telaConsultaEstoque;
    }

    public static Observador getTelaConsultaVenda() {
        return telaConsultaVenda;
    }
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        telaConsultaEstoque = new gui.TelaConsultaEstoque();
        telaConsultaVenda = new gui.TelaConsultaVenda();
        bmMenu = new javax.swing.JMenuBar();
        mArquivo = new javax.swing.JMenu();
        mVenda = new javax.swing.JMenuItem();
        mSair = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        telaConsultaEstoque.setName("telaConsultaEstoque"); // NOI18N

        telaConsultaVenda.setName("telaConsultaVenda"); // NOI18N

        bmMenu.setName("bmMenu"); // NOI18N

        mArquivo.setText("Principal");
        mArquivo.setName("mArquivo"); // NOI18N

        mVenda.setText("Cadastrar venda");
        mVenda.setName("mVenda"); // NOI18N
        mArquivo.add(mVenda);

        mSair.setText("Sair");
        mSair.setName("mSair"); // NOI18N
        mArquivo.add(mSair);

        bmMenu.add(mArquivo);

        setJMenuBar(bmMenu);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap(415, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(telaConsultaEstoque, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(telaConsultaVenda, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(telaConsultaEstoque, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(telaConsultaVenda, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(22, Short.MAX_VALUE))
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-808)/2, (screenSize.height-623)/2, 808, 623);
    }// </editor-fold>//GEN-END:initComponents



    private class MenuListener implements ActionListener {

        public void actionPerformed(ActionEvent e) {
            if(e.getSource().equals(mSair)) {
                System.exit(0);
            }
            if(e.getSource().equals(mVenda))
            {
                if(!telaVenda.isVisible())
                   telaVenda.setVisible(true);
                else
                   telaVenda.requestFocus();
            }
        }
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenuBar bmMenu;
    private javax.swing.JMenu mArquivo;
    private javax.swing.JMenuItem mSair;
    private javax.swing.JMenuItem mVenda;
    private static gui.TelaConsultaEstoque telaConsultaEstoque;
    private static gui.TelaConsultaVenda telaConsultaVenda;
    // End of variables declaration//GEN-END:variables

}
